package uk.ac.glasgow.demosocs.impl.ui;

import uk.ac.glasgow.clui.ArgumentsDescription;
import uk.ac.glasgow.clui.CommandDescription;
import uk.ac.glasgow.clui.MinimumArguments;
import uk.ac.glasgow.clui.SystemCommand;
import uk.ac.glasgow.clui.SystemCommandException;
import uk.ac.glasgow.demosocs.VotingSystem;

@MinimumArguments(2)
@CommandDescription("Sets the currently selected user.")
@ArgumentsDescription("<guid> <password>")
public class SetCurrentUserCommand extends SystemCommand<VotingSystem> {

	// in case that the username and password are in the db this will be 
	// changed to true
	public static boolean loggedin = false;
	
	public SetCurrentUserCommand(VotingSystem facade) {
		super(facade);
	}

	@Override
	public String processCommand(String[] arguments)
			throws SystemCommandException {
		
				
		// The main menu for the system 
		String borderMenu = "-----------------------------------------\n" +
							"| Welcome to the Voting System CLI      |\n" +
							"-----------------------------------------\n" +
							"| publish                               |\n" +
							"| election                              |\n" +
							"| create                                |\n" +
							"| edit                                  |\n" +
							"| elections                             |\n" +
							"| nominate                              |\n" +
							"| accept                                |\n" +
							"| nominations                           |\n" +
							"| cast                                  |\n" +
							"| logout                                |\n" +
							"-----------------------------------------\n" +
							"| \"usage/u <command>\" for parameters    |\n" +
							"| \"man/m <command>\" for more info       |\n" +
							"-----------------------------------------\n" ;
		
		
		
		String userName = arguments[0];
		String password = arguments[1];
		
		boolean result = facade.setCurrentUser(userName,password);
		
		// TODO This needs to be implemented 
		loggedin = true;
		
		if(loggedin)
			System.out.println(borderMenu);
		
		if (result) return "User ["+userName+"] now the current user.";
		else return "Invalid username or password";
	}
}
